import request from '@/utils/request'
/**
 * @description 获取用户列表（模板）
 * @param data
 */
export const getUserPages = (data = {}) => {
  return request.post('/boss/user/getUserPages', {
    ...data
  })
}

/**
 * @description 获取课程列表
 * @param data
 */
export const getCourseLists = (data = {}) => {
  // 请求模板
  const oldData = {
    currentPage: 1,
    pageSize: 10,
    courseName: '',
    status: null
  }
  return request.post('/boss/course/getQueryCourses', {
    ...oldData,
    ...data
  })
}

/**
 * @description 课程上下架
 */
export const changeState = (data = {}) => {
  const oldData = {
    courseId: '',
    status: ''
  }
  return request.get('/boss/course/changeState', {
    params: {
      ...oldData,
      ...data
    }
  })
}

/**
 * @description 保存或更新课程
 */
export const saveOrUpdateCourse = (data = {}) => {
  return request.post('/boss/course/saveOrUpdateCourse', {
    ...data
  })
}

/**
 * @description 上传图片/boss/course/upload
 */
export const uploadFile = (
  data = {},
  onUploadProgress?: (progressEvent: ProgressEvent) => void
) => {
  return request({
    method: 'POST',
    url: '/boss/course/upload',
    data,
    onUploadProgress
  })
}

/**
 * @description 根据id查询课程信息
 */

export const findCourseDetailById = (courseId: number | string) => {
  return request.get('/boss/course/getCourseById', {
    params: {
      courseId
    }
  })
}

/**
 * @description 获取章节内容
 */
export const getSectionAndLesson = (courseId: number | string) => {
  return request.get('/boss/course/section/getSectionAndLesson', {
    params: {
      courseId
    }
  })
}

/**
 * @description 更新节点
 *
 */
export const saveOrUpdateSection = (data = {}) => {
  return request.post('/boss/course/section/saveOrUpdateSection', {
    ...data
  })
}
export const saveOrUpdateLesson = (data = {}) => {
  return request.post('/boss/course/lesson/saveOrUpdate', {
    ...data
  })
}

export const addLesson = (data = {}) => {
  return request.post('/boss/course/lesson/saveOrUpdate', {
    ...data
  })
}

export const getImgAuth = () => {
  return request.get('/boss/course/upload/aliyunImagUploadAddressAdnAuth.json')
}
interface GetVideoAuthInterface {
  fileName?: string;
  imageUrl?: string;
}
export const getVideoAuth = (data: GetVideoAuthInterface = {}) => {
  return request.get(
    '/boss/course/upload/aliyunVideoUploadAddressAdnAuth.json',
    {
      params: {
        ...data
      }
    }
  )
}
interface TransCodeRequest {
  lessonId?: string | number;
  coverImageUrl?: string;
  fileId?: string;
  fileName?: string;
  sectionId?: string;
}
export const transCodeRequest = (data: TransCodeRequest = {}) => {
  return request.post('/boss/course/upload/aliyunTransCode.json', {
    ...data
  })
}
export const transCodePercent = (lessonId?: string | number) => {
  return request.get('/boss/course/upload/aliyunTransCodePercent.json', {
    params: {
      lessonId
    }
  })
}
